package cn.wolfcode.luowowo.website.util;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常类
 *
 * @ControllerAdvice 控制层功能增强注解
 * 给请求映射方法进行功能增强: 在进入映射方法前或者执行完映射后进行功能增强
 * 此处功能: 执行映射方法后出现异常后怎么处理
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object logic(Exception e) {
        e.printStackTrace();
        return new AjaxResult(false, e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object runtime(Exception e) {
        e.printStackTrace();
        return new AjaxResult(false, "系统繁忙,请联系10086");
    }
}
